package com.ruoyi.puyu.service.impl;

import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.puyu.domain.PuyuCoach;
import com.ruoyi.puyu.mapper.PuyuCoachMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.puyu.mapper.PuyuStrengthTestMapper;
import com.ruoyi.puyu.domain.PuyuStrengthTest;
import com.ruoyi.puyu.service.IPuyuStrengthTestService;

/**
 * 体能测试Service业务层处理
 * 
 * @author wusongwen
 * @date 2024-05-01
 */
@Service
public class PuyuStrengthTestServiceImpl implements IPuyuStrengthTestService 
{
    private static final Logger logger = LoggerFactory.getLogger(PuyuStrengthTestServiceImpl.class);
    @Autowired
    private PuyuStrengthTestMapper puyuStrengthTestMapper;
    @Autowired
    private PuyuCoachMapper puyuCoachMapper;

    /**
     * 查询体能测试
     * 
     * @param strengthTestId 体能测试主键
     * @return 体能测试
     */
    @Override
    public PuyuStrengthTest selectPuyuStrengthTestByStrengthTestId(Long strengthTestId)
    {
        return puyuStrengthTestMapper.selectPuyuStrengthTestByStrengthTestId(strengthTestId);
    }

    /**
     * 查询体能测试列表
     * 
     * @param puyuStrengthTest 体能测试
     * @return 体能测试
     */
    @Override
    public List<PuyuStrengthTest> selectPuyuStrengthTestList(PuyuStrengthTest puyuStrengthTest)
    {
        return puyuStrengthTestMapper.selectPuyuStrengthTestList(puyuStrengthTest);
    }

    /**
     * 新增体能测试
     * 
     * @param puyuStrengthTest 体能测试
     * @return 结果
     */
    @Override
    public int insertPuyuStrengthTest(PuyuStrengthTest puyuStrengthTest)
    {
        PuyuCoach puyuCoach = puyuCoachMapper.selectPuyuCoachByUserId(SecurityUtils.getUserId());
        if (null == puyuCoach) {
            logger.info("您不是教练，用户ID：{}", SecurityUtils.getUserId());
            throw new ServiceException(MessageUtils.message("coach.not.match"));
        }
        puyuStrengthTest.setCoachId(puyuCoach.getCoachId());
        puyuStrengthTest.setCreateTime(DateUtils.getNowDate());
        return puyuStrengthTestMapper.insertPuyuStrengthTest(puyuStrengthTest);
    }

    /**
     * 修改体能测试
     * 
     * @param puyuStrengthTest 体能测试
     * @return 结果
     */
    @Override
    public int updatePuyuStrengthTest(PuyuStrengthTest puyuStrengthTest)
    {
        puyuStrengthTest.setUpdateTime(DateUtils.getNowDate());
        return puyuStrengthTestMapper.updatePuyuStrengthTest(puyuStrengthTest);
    }

    /**
     * 批量删除体能测试
     * 
     * @param strengthTestIds 需要删除的体能测试主键
     * @return 结果
     */
    @Override
    public int deletePuyuStrengthTestByStrengthTestIds(Long[] strengthTestIds)
    {
        return puyuStrengthTestMapper.updatePuyuStrengthTestByStrengthTestIds(strengthTestIds);
    }

    /**
     * 删除体能测试信息
     * 
     * @param strengthTestId 体能测试主键
     * @return 结果
     */
    @Override
    public int deletePuyuStrengthTestByStrengthTestId(Long strengthTestId)
    {
        return puyuStrengthTestMapper.deletePuyuStrengthTestByStrengthTestId(strengthTestId);
    }
}
